home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / Mops 2.7 / Mops Manual / Demo folder / Sin < prev    next >
Text File  |  1994-10-23  |  3KB  |  74 lines

  1. \ These classes obtain the sine and cos of an angle by table lookup.
  2. \ Modified from the original Neon version by Mike Hore.
  3.  
  4. \ The main class is ANGLE, which has SIN: and COS: methods that look
  5. \ up a table defined with the TRIGTABLE class.
  6.  
  7.  
  8. need    struct1
  9.  
  10. :class  TRIGTABLE    super{ wArray }
  11.  
  12.     4    wArray  AXISVALS                \ 90 degree values
  13.  
  14. :m SIN:  { degree \ quadrant  -- sin }
  15.                         \ Looks up a sin * 10000 of an angle
  16.  
  17.     degree 360 mod                    \ Put angle in range -359 to +359
  18.     dup 0<  IF   360 +   THEN        \ Now 0 to +359
  19.     90  /mod                \ Convert degree to range 0-89 and get quadrant
  20.     -> quadrant   -> degree   
  21.     degree                            \ Test for an axis
  22.     NIF     quadrant  at: axisVals    \ If an axis, get value
  23.     ELSE    quadrant  1 and            \ True for "mirror" quadrants 1 and 3
  24.         IF    90 degree  -            \ Create mirror image
  25.         ELSE    degree
  26.         THEN
  27.         at: self                    \ Get sin for this degree
  28.         quadrant 2 and                \ true for "negative" quadrants 2 and 3
  29.         IF  negate  THEN
  30.     THEN  ;m
  31.  
  32. :m  COS:    \ (degree -- cos )
  33.     90 +   sin: self   ;m            \ Cos is sin shifted by 90 degrees
  34.  
  35. :m  CLASSINIT:
  36.     0 0 to: axisvals    10000 1 to: axisvals  
  37.     0 2 to: axisvals   -10000 3 to: axisvals    ;m
  38.  
  39. ;class
  40.  
  41. 90  TrigTable  SINES      \ system-wide table of sines
  42.  
  43. : 's        \ ( val degree -- )    Fills a Sin table entry
  44.     to: sines   ;
  45.  
  46. 00000 00 's   00175 01 's   00349 02 's   00524 03 's   00698 04 's
  47. 00872 05 's   01045 06 's   01219 07 's   01392 08 's   01571 09 's
  48. 01736 10 's   01908 11 's   02079 12 's   02250 13 's   02419 14 's
  49. 02588 15 's   02756 16 's   02924 17 's   03090 18 's   03256 19 's
  50. 03420 20 's   03584 21 's   03746 22 's   03907 23 's   04067 24 's
  51. 04226 25 's   04384 26 's   04540 27 's   04695 28 's   04848 29 's
  52. 05000 30 's   05150 31 's   05299 32 's   05446 33 's   05592 34 's
  53. 05736 35 's   05878 36 's   06018 37 's   06157 38 's   06293 39 's
  54. 06428 40 's   06561 41 's   06691 42 's   06820 43 's   06947 44 's
  55. 07071 45 's   07193 46 's   07314 47 's   07431 48 's   07547 49 's
  56. 07660 50 's   07771 51 's   07880 52 's   07986 53 's   08090 54 's
  57. 08192 55 's   08290 56 's   08387 57 's   08480 58 's   08572 59 's
  58. 08660 60 's   08746 61 's   08829 62 's   08910 63 's   08988 64 's
  59. 09063 65 's   09135 66 's   09205 67 's   09272 68 's   09336 69 's
  60. 09397 70 's   09455 71 's   09511 72 's   09563 73 's   09613 74 's
  61. 09659 75 's   09703 76 's   09744 77 's   09781 78 's   09816 79 's
  62. 09848 80 's   09877 81 's   09903 82 's   09925 83 's   09945 84 's
  63. 09962 85 's   09976 86 's   09986 87 's   09994 88 's   09998 89 's
  64.  
  65. : SIN    sin: sines   ;
  66. : COS    cos: sines   ;
  67.  
  68. :class  ANGLE    super{ int }
  69.  
  70. :m  SIN:    get: self   sin    ;m
  71. :m  COS:    get: self   cos    ;m
  72.  
  73. ;class
  74.